// index.ts - Web Monitor SDK 统一导出
// @/utils/monitor/index.ts

// 导出主要类和接口
export { WebMonitorSDK, webMonitor } from './WebMonitorSDK';
export type { 
  MonitorConfig, 
  MonitorEvent, 
  EventType,
  ErrorEventData,
  PerformanceEventData,
  ApiEventData,
  BehaviorEventData,
  CustomEventData,
  EventContext,
  DeviceInfo
} from './MonitorTypes';

// 导出工具函数
export { 
  generateUUID, 
  generateShortUUID, 
  generateSessionId,
  getDeviceId 
} from './utils/uuid';

export { 
  compress, 
  decompress, 
  smartCompress,
  isCompressionSupported 
} from './utils/compress';

export { 
  getEventContext, 
  getDeviceInfo,
  getMemoryInfo,
  getBatteryInfo 
} from './utils/context';

export {
  getPlatform,
  isH5,
  isWeixin,
  isAlipay,
  isApp,
  isMiniProgram,
  getSystemInfo,
  getStatusBarHeight,
  getNavBarHeight,
  getSafeArea,
  px2rpx,
  rpx2px,
  getScreenInfo,
  getNetworkType,
  checkApiSupport,
  platformFeatures
} from './utils/platform';

// 导出采集器（高级用法）
export { ErrorCollector } from './collectors/ErrorCollector';
export { PerformanceCollector } from './collectors/PerformanceCollector';
export { NetworkCollector } from './collectors/NetworkCollector';
export { BehaviorCollector } from './collectors/BehaviorCollector';

// 导出上报器（高级用法）
export { Reporter } from './reporter/Reporter';

/**
 * 快速初始化监控SDK
 * @param config 监控配置
 * @example
 * ```typescript
 * import { initMonitor } from '@/utils/monitor';
 * 
 * initMonitor({
 *   appId: 'your-app-id',
 *   appVersion: '1.0.0',
 *   endpoint: 'https://your-api.com/monitor',
 *   enableDebug: true
 * });
 * ```
 */
export function initMonitor(config: MonitorConfig): void {
  webMonitor.init(config);
}

/**
 * 追踪自定义事件
 * @param eventName 事件名称
 * @param data 事件数据
 * @example
 * ```typescript
 * import { trackEvent } from '@/utils/monitor';
 * 
 * trackEvent('button_click', { buttonId: 'submit', page: 'login' });
 * ```
 */
export function trackEvent(eventName: string, data?: any): void {
  webMonitor.trackCustomEvent(eventName, data);
}

/**
 * 追踪错误
 * @param error 错误信息
 * @param extra 额外信息
 * @example
 * ```typescript
 * import { trackError } from '@/utils/monitor';
 * 
 * try {
 *   // some code
 * } catch (error) {
 *   trackError(error, { context: 'user-action' });
 * }
 * ```
 */
export function trackError(error: Error | string, extra?: any): void {
  webMonitor.trackError(error, extra);
}

/**
 * 设置用户ID
 * @param userId 用户ID
 * @example
 * ```typescript
 * import { setUserId } from '@/utils/monitor';
 * 
 * setUserId('user_12345');
 * ```
 */
export function setUserId(userId: string): void {
  webMonitor.setUserId(userId);
}

/**
 * 设置元数据
 * @param metadata 元数据
 * @example
 * ```typescript
 * import { setMetadata } from '@/utils/monitor';
 * 
 * setMetadata({ 
 *   version: '2.0.0',
 *   feature: 'new-ui' 
 * });
 * ```
 */
export function setMetadata(metadata: Record<string, any>): void {
  webMonitor.setMetadata(metadata);
}

/**
 * 立即上报数据
 * @example
 * ```typescript
 * import { flush } from '@/utils/monitor';
 * 
 * await flush();
 * ```
 */
export async function flush(): Promise<void> {
  return webMonitor.flush();
}

/**
 * 获取监控状态（调试用）
 * @example
 * ```typescript
 * import { getMonitorStatus } from '@/utils/monitor';
 * 
 * console.log(getMonitorStatus());
 * ```
 */
export function getMonitorStatus(): {
  config: MonitorConfig | undefined;
  sessionId: string;
  collectors: Record<string, any>;
  reporter: any;
} {
  return {
    config: webMonitor.getConfig(),
    sessionId: webMonitor.getSessionId(),
    collectors: webMonitor.getCollectorsStatus(),
    reporter: webMonitor.getReporterStatus()
  };
}

// 默认导出
export default {
  init: initMonitor,
  track: trackEvent,
  trackError,
  setUserId,
  setMetadata,
  flush,
  getStatus: getMonitorStatus,
  webMonitor
}; 